/*
*  服务端：
*  1- 下载依赖
*      cnpm install express socket.io
*  2- 创建其于socket的服务*
* */
const http = require("http");
const path = require("path");
const express = require("express");
const socketIo = require("socket.io");

const app = express();
const httpServer = http.createServer(app);
const io = socketIo(httpServer);// io是一个对象,可以通过该对象创建前后端的通讯
// 连接websocket服务,
// 回调函数接收一个参数
io.on("connection",function(socket){
    console.log("连接成功",socket.id);
    socket.on("info",function(a,b,c,d){
        console.log(a,b,c,d);
        // 向前端推送数据
        socket.emit("my",10,20,30,40);
    })
    socket.on("disconnect",function(){
        console.log("断开连接",socket.id);
    })
})
app.use(express.static(path.resolve(__dirname,"../html")))
httpServer.listen(80,function(){
    console.log("success");
})
